package ${basePackage}.action;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.hibernate.Page;

import ${basePackage}.entity.${beanName};
import ${basePackage}.service.${beanName}Service;
import com.kingee.comm.common.action.AppBaseAction;

public class ${beanName}Action extends AppBaseAction {

	private ${beanName} record = new ${beanName}();

	private Page<${beanName}> page = new Page<${beanName}>(20,true);
	
	@Autowired
	private ${beanName}Service service;
	
	public void prepare() throws Exception {
		if (!StringUtils.isBlank(record.getId())) {
			record = (${beanName})service.selectByPrimaryKey(record.getId());
		}
	}

	/**
	 * 列表主页面
	 */
	public String list() throws Exception {
		service.findAllPage(page, record);
		return "list";
	}
	
	/**
	 * 新增修改
	 */
	public String save() throws Exception {
		if (!StringUtils.isBlank(record.getId())) {
			service.update(record);
		} else {
			service.insert(record);
		}
		
		messageUrl("保存成功", getParentUri());
		return null;
	}

	/**
	 * 单个删除
	 */
	public String delete() throws Exception {
		messageUrl(null, getParentUri());
		return null;
	}

	public String input() throws Exception {
		return "input";
	}
	
	public ${beanName} getRecord() {
		return record;
	}

	public void setRecord(${beanName} record) {
		this.record = record;
	}

	public Page<${beanName}> getPage() {
		return page;
	}
	public void setPage(Page<${beanName}> page) {
		this.page = page;
	}
	
}
